package com.aisoback.exception;

import com.aisoback.common.BaseResponse;
import com.aisoback.common.Code;
import com.aisoback.common.ResultUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 处理业务异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> BusinessException(BusinessException e) {
        return ResultUtils.error(e.getCode(), e.getMessage());
    }

    /**
     * 处理系统异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> RuntimeException(RuntimeException e) {
        return ResultUtils.error(Code.SYSTEM_ERROR, e.getMessage());
    }
}
